var Main = RichBase.extend({
	statics : {
		currentPage : 0,
		last : "",
		oData : {},
		queryState : {
			loading : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">加载数据...</p><img src="images/other/loading_1.gif" alt="" /></li>',
			empty : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">没有产品...</p></li>',
			fail : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">请求失败...</p></li>',
			unlogin : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">登录过期，请重新登录...</p></li>',
			timeout : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">网络请求超时...</p></li>',
			serverError : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">请求出错...</p></li>'
		},
		isObjEmpty : function(obj){
			for(var i in obj){
				return false;
			}
			return true;
		}
	},
	EVENTS : {
		"click" : {
			".conmone .save_btn" : "save_btnClick"
		}
	},
	init : function(opt){
		
	},
	save_btnClick : function(){
		
		
		var postData = $("form#conpu_form").serialize();
		//console.log(postData)
		$.ajax({
			//type:'POST',url: 'http://www.12301.cc/admin/pppp.php',data: postData, dataType:'json',
			type:'POST',url: 'http://www.12301.cc/call/jh_coupon.php',data: postData, dataType:'json',
		}).done(function(res) {
			if(res.status=="success"){
				PFT_GLOBAL.U.Alert("success",'<p style="width:120px">'+res.msg+'</p>');
			
			}
			else{
				PFT_GLOBAL.U.Alert("fail",'<p style="width:120px">'+res.msg+'</p>');
			}
		})
		
		
		
	},
	query : function(opt){
		var that = this;
		var opt = opt || {};
		var pageSize = opt.pageSize || 15;
		var last = opt.last || "";
		var provice = opt.provice || "";
		var city = opt.city || "";
		var title = opt.title || "";
		var ttimeout = opt.ttimeout || 20 * 60 * 1000;
		var data = {
			pageSize : pageSize,
			last : last,
			provice : provice,
			city : city,
			title : title,
			async : 1
		};
		var listUl = $("#mlistUl");
		var pagenavW = $("#pagenavW");
		var status = this.statics.queryState;
		PFT.Ajax({
			url : "product_package.html",
			type : "GET",
			dataType : "json",
			ttimeout : ttimeout,
			data : data,
			loading : function(){
				listUl.html(status["loading"]);
				pagenavW.hide();
			},
			removeLoading : function(res){
				that.statics.last = "";
				that.statics.currentPage += 1;
				listUl.html("");
				pagenavW.show();
			},
			timeout : function(){ listUl.html(status["timeout"]);},
			serverError : function(){ listUl.html(status["serverError"]);}
		},function(res){
			var code = res.code;
			var lists = res.lists;
			var last = res.last;
			if(code==200){
				if(!that.statics.isObjEmpty(lists)){
					that.statics.oData[that.statics.currentPage] = res;
					that.buildHtml(res);
				}else{
					listUl.html(status["empty"]);
					if(provice) that.fire("search_empty",res);
				}
				that.statics.last = last;
				if(!last){
					that.fire("no_next",res);
				}else{
					that.fire("has_next",res);
				}
			}else if(code==0){
				listUl.html(status["unlogin"]);
			}else{
				listUl.html(status["fail"]);
			}
		})
	}

});





var search_all = RichBase.extend({
	
	statics : {},
	EVENTS : {
		"focus" : {
			".formInp" : "onInputFocus"
		},
		"blur" : {
			".formInp" : "onInputBlur"
		},
		"click" : {
			// ".ticket_c" : "BtnClick"
			".coutTd .countBtn" : "onCountBtnClick",
			".coutTd .countBtn" : "onCountBtnClick",
			".ticket_c" : "BtnClick"
			//".clickBox" : "clickBox"
			}
	},
	init : function(opt){
		this.onload();
	},
	
	onload : function(that,e){
		
		var that = this;
		$('#prodSearchInp').text('');
		$(".cleartxt").click(function(){
			$('#prodSearchInp').val('');
			$(this).css("display","none");
			$("#lid_id").val('');
		});
		$("#prodSearchInp").keyup(function(){
				
			var sth=$('#prodSearchInp').val();
			var i=0;
			
			$("#prodList li").each(function(){
		
				var n=$(this).text().indexOf(sth);
				
				if(n==-1){
					$(this).css("display","none");
					
				}else{
					i+=1
					$(this).css("display","block");
				}
			});
			if(i==0){
				//PFT_GLOBAL.U.Alert("success",'<p style="width:120px">抱歉暂无匹配搜索结果</p>');
				$("#prodList").css("display","none");
				
			}else{
				//$(".searchmsg").css("display","none");
				$("#prodList").css("display","block");
			} 
		});
		PFT.Ajax({
			url : "http://www.12301.cc/api/inside/saleProds.php?act=lands",
			type : "post",
			dataType : "json",
		},function(res){
			
			that.list_search(res); 
		})
	},
	
	
	
	list_search : function(data){
	var that = this;
	var list = data.lists;
	for(var i=0;i<list.length;i++){
	    $("#prodList").append("<li data="+list[i].id+">"+list[i].title+"</li>");
	}
	$("#prodList li").eq(0).addClass("setbg");
	$("#prodList li").click(function(){
	
		$(".must_sec").css("display","none");
		var i=$(this).index();
		$("#prodSearchInp").val(list[i].title);
		$("#prodList li").removeClass("setbg");
		$("#prodList li").eq(i).addClass("setbg");
		$("#prodList").css("display","none"); 
		$("#lid_id").val(list[i].id);
		var lid_b = list[i].id;
		//console.log(lid_b)
		that.data_list(lid_b);
        $(".cleartxt").css("display","block");
	});
	$("#prodSearchInp").click(function(){
        if($("#prodList").css("display")=='block')
            $("#prodList").css("display","none");
			
        else
		    $("#prodList").css("display","block");
			$(".tbBind").hide();
		});
	},
	//新加入的搜索 展示
	data_list : function(opt){
		var that = this;
		var opt = opt || {};
		var data = {
			//lid:7036
			lid:opt
		};
		var url = "http://www.12301.cc/api/inside/saleProds.php?act=prods";
		var url_id ="1";
		var listUl = $("#mlistUl");
		var pagenavW = $("#pagenavW");
		var status = this.statics.queryState;
		PFT.Ajax({
			//url : "product_package.html", 
			url : url,
			type : "GET",
			dataType : "json",
			data : data
		},function(res){
			var code = res.status;
			var lists = res.lists;
			if(code=="success"){
					var conf_type = $(".conf_type").val();
					if(conf_type=="0"){
						var type = "0";
						that.buildHtml(res,type);
					}
					else{
						var type = "1";
						that.buildHtml(res,type);
					}
				}
		})
	},
	buildHtml : function(res,type){
			var that = this;
			var code = res.code;
			var lists = res.lists;
			var length = res.length;
			var str = "";
			var item_a = $("#itemTpl").html();
			var item_div = $("#itemTpl_tr").html();
			var item_con = $("#itemTpl_con").html();
			var result = "";
			var listUl = $("#mlistUl");
			var pagenavW = $("#pagenavW");
			var list = lists;
			if(list==""){
				
				PFT_GLOBAL.U.Alert("fail",'<p style="width:240px">该产品暂无票类</p>');
				
			}
			var contents="";
			for(var i in list){
					var id =list[i]["pid"];
					var keywords =list[i]["ttitle"];
					var ltitle =list[i]["ltitle"];
					contents=contents+"<li title="+ltitle+" tttile="+keywords+" data-id="+id+" class=\"add_list\">"+keywords+"</li>";
				}
			$(".order_ul").html(contents); 
		}
	});
new search_all({container:$("#qunaer_select")});
new Main({container:$("#conmone")});